#!/usr/bin/python
"""This file samples the sequences in given alignment file based on total samples required.

Sampling methods available are boltzmann and fermi-dirac."""

# by Vineet Gupta <vineet@ural.wustl.edu>
# sample.py 1-27-2007 13:50

# TO DO:
# 

import sys
from pdf import fermi_dirac
from pdf import boltzmann

usage = '''Usage: python sample.py [file-name] [0 or 1] [number of samples required]
where file-name is file containing alignments and 0 and 1 singifies probability distribution to be used.
0 for Fermi-Dirac and 1 for Boltzmann.'''

try:
    file = open(sys.argv[1])
    
    if sys.argv[2] != '0' and sys.argv[2] != '1':
        raise Exception
    if len(sys.argv)!= 4:
        raise Exception
except:
    print usage
    sys.exit(1)
    
# all_sequences contains all the alignments in file
all_sequences = file.readlines()

# remove newline from all the sequences
for i in xrange(len(all_sequences)):
    all_sequences[i] = (all_sequences[i]).strip()

# True matrix for half site binding for Mnt protein
hs =  [0.14, 0.06, 0.15, 0.23, 0.40, 0.10, 0.21, \
0.07, 0.10, 0.01, 0.08, 0.30, 0.79, 0.43, \
0.75, 0.14, 0.76, 0.63, 0.10, 0.03, 0.15, \
0.04, 0.70, 0.08, 0.06, 0.20, 0.08, 0.21]

if sys.argv[2] == '0':
    # sampled using fermi dirac
    samples = fermi_dirac(all_sequences, int(sys.argv[3]))
else:
    # samples using boltzmann
    samples = boltzmann(hs, all_sequences, int(sys.argv[3]))
    
for s in samples:
    print s

